#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "perceptron.h"

#define DATA_SIZE 4
#define DATA_DIM 2

double **input;
double *output;

void
read_data()
{
	input = (double **) calloc (DATA_SIZE, sizeof(double*));
	output = (double *) calloc (DATA_SIZE, sizeof(double));

	input[0] = (double *) calloc (DATA_DIM, sizeof(double));
	input[0][0] = 0;
	input[0][1] = 0;
	output[0] = 0;
	
	input[1] = (double *) calloc (DATA_DIM, sizeof(double));
	input[1][0] = 0;
	input[1][1] = 1;
	output[1] = 1;

	input[2] = (double *) calloc (DATA_DIM, sizeof(double));
	input[2][0] = 1;
	input[2][1] = 0;
	output[2] = 1;

	input[3] = (double *) calloc (DATA_DIM, sizeof(double));
	input[3][0] = 1;
	input[3][1] = 1;
	output[3] = 1;
}

void
test(Perceptron &p)
{
	int i;
	double out;

	printf("\nTEST:\n\n");

	for (i = 0; i < DATA_SIZE; i++)
	{
		out = p.RunNetwork(input[i]);
		printf("%lf %lf = %lf\n", input[i][0], input[i][1], out);
	}
}


void
train_net(Perceptron &p)
{
	p.Train(input, output, DATA_SIZE);
}


int 
main(int argc, char **argv)
{
	Perceptron p(2, 1000, 1.0);

	read_data();
	train_net(p);
	test(p);

	return 0;
}

